<template>
  <div>
    <Form label-position="right" :label-width="400" :model="recruitItem">
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">社会统一信用代码：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aab003" placeholder="请输入社会统一信用代码"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">单位名称：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aab004" placeholder="请输入单位名称"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">所属行业名称：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="hangyes" @on-change="hangyeye">
            <Option v-for="items in hangyelist" :value="JSON.stringify(items)" :key="items.value">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">所属行业代码：</Col>
        <Col span="6" class="ivu-form-item-content"> <!--recruitItem.aab023-->
          <Input v-model="recruitItem.aab023" placeholder="请输入所属行业代码" readonly></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">经济类型：</Col>
        <Col span="6" class="ivu-form-item-content">
        <!--  <Input v-model="recruitItem.aab020" placeholder="请输入经济类型"></Input>-->
          <Select v-model="recruitItem.aab020" >
            <Option v-for="items in jingjilist" :value="items.value" :key="items.value">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">产业类别：</Col>
        <Col span="6" class="ivu-form-item-content">
<!--          <Input v-model="recruitItem.aab054" placeholder="请输入产业类别"></Input>-->
          <Select v-model="recruitItem.aab054">
            <Option v-for="items in chanyelist" :value="items.value" :key="items.value">{{ items.label }}</Option>
          </Select>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">单位地址：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aae006" placeholder="请输入单位地址"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">单位简介：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aab092" type="textarea" :autosize="{maxRows: 7,minRows: 1}" placeholder="请输入单位简介"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">联系人：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aae004" placeholder="请输入联系人"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">联系电话：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aae005" placeholder="请输入联系电话"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">电子邮件：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aae159" placeholder="请输入电子邮件"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">备注：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aae013" type="textarea" :autosize="{maxRows: 7,minRows: 1}" placeholder="请输入备注"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">经办日期：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="recruitItem.aae036" v-if="recruitItem.aae036 === ''" placeholder="请点击获取当前时间" @on-focus="saveTime"></Input>
          <Input v-model="recruitItem.aae036" v-else readonly placeholder="请点击获取当前时间" ></Input>
        </Col>
      </Row>
      <Row v-for="(item, index) in formDynamic.items" :key="index + 100">
        <div v-if="item.status">
        <Col span="5" class="ivu-form-item-label">招聘工种名称：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="namea" class="add"  @on-change="gongzhonga">
            <Option v-for="items in jobList" :value="JSON.stringify(items)" :key="items.id">{{ items.aca112 }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">招聘工种代码：</Col>
        <Col span="6" class="ivu-form-item-content">
       <!--   <Select v-model="item.code" class="add"  >
            <Option v-for="items in jobList" :value="items.id" :key="items.id">{{ items.label }}</Option>
          </Select>-->
          <Input v-model="item.code" placeholder="请输入招聘工种代码" readonly class="add" ></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">岗位描述：</Col>
        <Col span="6" class="ivu-form-item-content">
        <!--  <Input v-model="item.post" placeholder="请输入岗位描述" class="add"></Input>-->
          <Select v-model="item.post" class="add" @on-open-change="gwjieshao">
            <Option v-for="items in gangweiList" :value="items.label" :key="items.id">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">用工形式：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="item.type" class="add" @on-open-change="findTypeList">
            <Option v-for="items in typeList" :value="items.label" :key="items.id">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">男性人数：</Col>
        <Col span="6" class="ivu-form-item-content" style="width: 218px">
          <Input v-model="item.manNum" placeholder="请输入男性人数" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">女性人数：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.womNum" placeholder="请输入女性人数" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">兼招人数：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.num" placeholder="请输入兼招人数" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">最低年龄：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.limitAge" placeholder="请输入最低" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">最高年龄：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.maxAge" placeholder="请输入最高年龄" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">月薪下限：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.minSalary" placeholder="请输入月薪下限" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">月薪上限：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.maxSalary" placeholder="请输入月薪上限" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">福利待遇：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.fuli" placeholder="请输入福利待遇" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">最低文化程度：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="item.culture" class="add">
            <Option v-for="items in WHList" :value="items.value" :key="items.id">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">所学专业名称：</Col>
        <Col span="6" class="ivu-form-item-content">
       <!--   <Select v-model="item.zyName" class="add" @on-change="zynamea" >
            <Option v-for="items in ZYMCList" :value="items.label" :key="items.id">{{ items.label }}</Option>
          </Select>-->
          <Select v-model="zyname" class="add"  @on-change="zynamea">
            <Option v-for="items in ZYMCList" :value="JSON.stringify(items)" :key="items.id">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">所学专业代码：</Col>
        <Col span="6" class="ivu-form-item-content">
         <!-- <Select v-model="item.zyCode" class="add" >
            <Option v-for="items in ZYList" :value="items.value" :key="items.id">{{ items.label }}</Option>
          </Select>-->
          <Input v-model="item.zyCode" placeholder="请输入所学专业代码" readonly class="add" ></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">健康状况：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="item.health" class="add" >
            <Option v-for="items in jkList" :value="items.value" :key="items.value">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">最低从业年数：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.year" placeholder="请输入最低从业年数" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">工作详细地址：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.address" placeholder="请输入工作详细地址" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">工作地点行政区划名称：</Col>
        <Col span="6" class="ivu-form-item-content">
         <!-- <Input v-model="item.gzName" placeholder="请输入工作地点行政区划名称" class="add"></Input>-->
          <Select v-model="gzname" class="add"  @on-change="gznamea">
            <Option v-for="items in AddressList" :value="JSON.stringify(items)" :key="items.id">{{ items.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">工作地点行政区划：</Col>
        <Col span="6" class="ivu-form-item-content">
         <!-- <Select v-model="item.guihua" class="add">
            <Option v-for="items in AddressList" :value="items.id" :key="items.id">{{ items.label }}</Option>
          </Select>-->
          <Input v-model="item.guihua" placeholder="请输入工作地点行政区划" readonly class="add" ></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">备注：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.beizhu" placeholder="请输入备注" class="add"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">经办日期：</Col>
        <Col span="6" class="ivu-form-item-content">
          <DatePicker v-model="item.jingban" type="date" format="yyyy-MM-dd" placeholder="请选择上次失业时间" class="add" @on-change="time"></DatePicker>
        </Col>
        <Col span="5" class="ivu-form-item-label">有效期：</Col>
        <Col span="6" class="ivu-form-item-content">
          <DatePicker v-model="item.endTime" type="date" format="yyyy-MM-dd" placeholder="请选择有效期" class="add" @on-change="time"></DatePicker>
        </Col>
        </div>
      </Row>
      <Row class="mb20">
        <Col span="3">
          <Button type="dashed" long @click="handleAdd" icon="md-add">添加招聘信息</Button>
        </Col>
      </Row>
    </Form>
  </div>
</template>

<script>
import itemdata from '../itemdata'
import { date2str } from '@/api/eventlist'
import { createPost } from '@/api/post'
export default {
  props: {
    unemploymentItem1: Object
  },
  name: 'index.vue',
  data () {
    return {
      zyname: '',
      gzname: '',
      namea: '',
      hangyes: '',
      index: 1,
      recruitItem: {
        apiName: 'sq4dwkgdj',
        aab003: '',
        aab004: '',
        aab022: '',
        aab023: '',
        aab020: '',
        aae006: '',
        ifgs: '0',
        aab092: '',
        aae004: '',
        aae005: '',
        aae159: '',
        aae013: '',
        aae036: '',
        zpgw: []
      },
      formDynamic: {
        items: [
          {
            endTime: '',
            code: '',
            name: '',
            post: '',
            type: '',
            manNum: '',
            womNum: '',
            num: '',
            limitAge: '',
            maxAge: '',
            minSalary: '',
            maxSalary: '',
            fuli: '',
            health: '',
            culture: '',
            zyCode: '',
            year: '',
            address: '',
            zyName: '',
            guihua: '',
            gzName: '',
            beizhu: '',
            jingban: '',
            index: 1,
            status: 1
          }
        ]
      },
      jobList: [],
      jobNameList: [],
      typeList: [],
      WHList: itemdata.educationList,
      ZYList: [],
      ZYMCList: [],
      jkList: itemdata.physicalConditionList,
      AddressList: [],
      hangyelist: itemdata.industryList,
      jingjilist: itemdata.economicsTypelist,
      chanyelist: itemdata.industryCategoryList,
      gangweiList: []
    }
  },
  watch: {
    // 回显
    unemploymentItem1 (a) {
      this.recruitItem = a
      this.hangyes = a.aab022
      this.formDynamic.items = this.recruitItem.zpgw
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        let data1 = {
          aae031: date2str(this.formDynamic.items[i].endTime),
          aca111: this.formDynamic.items[i].code,
          aca112: this.formDynamic.items[i].name,
          acb216: this.formDynamic.items[i].post,
          acb20A: this.formDynamic.items[i].type,
          acb21D: this.formDynamic.items[i].manNum,
          acb21E: this.formDynamic.items[i].womNum,
          acb21F: this.formDynamic.items[i].num,
          acb221: this.formDynamic.items[i].limitAge,
          acb222: this.formDynamic.items[i].maxAge,
          acb241: this.formDynamic.items[i].minSalary,
          acb242: this.formDynamic.items[i].maxSalary,
          acb244: this.formDynamic.items[i].fuli,
          aac011: this.formDynamic.items[i].culture,
          aac183: this.formDynamic.items[i].zyCode,
          aac184: this.formDynamic.items[i].zyName,
          aac033: this.formDynamic.items[i].health,
          aac217: this.formDynamic.items[i].year,
          acb21s: this.formDynamic.items[i].address,
          aab301: this.formDynamic.items[i].guihua,
          aaa021: this.formDynamic.items[i].gzName,
          aae013: this.formDynamic.items[i].beizhu,
          aae036: date2str(this.formDynamic.items[i].jingban)
        }
        this.recruitItem.zpgw.push(data1)
      }
      console.log(a, '555555555555555555888')
    }
  },
  methods: {
    time () {
      /* this.form.aac006 = date2str(this.form.aac006)
      this.form.aac007 = date2str(this.form.aac007) */
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        this.formDynamic.items[i].jingban = date2str(this.formDynamic.items[i].jingban)
        this.formDynamic.items[i].endTime = date2str(this.formDynamic.items[i].endTime)
      }
    },
    // 招聘工种代码
    gongzhong () {
      let data = {
        apiName: 'sq4gjzyfl'
      }
      createPost(data).then(ret => {
        if (ret.data.data.result === '1') {
          this.jobList = ret.data.data.data
        }
      })
    },
    gongzhonga (val) {
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        this.formDynamic.items[i].name = JSON.parse(val).aca112
        this.formDynamic.items[i].code = JSON.parse(val).parentid
      }
    },
    gznamea (val) {
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        this.formDynamic.items[i].gzName = JSON.parse(val).label
        this.formDynamic.items[i].guihua = JSON.parse(val).id
      }
    },
    hangyeye (val) {
      this.recruitItem.aab022 = JSON.parse(val).label
      this.recruitItem.aab023 = JSON.parse(val).value
    },
    // 工作地点行政区划名称
    findAddressList () {
      let data = {
        /* apiName: 'sq4gjzyfl' */
        apiName: 'sq4areacode',
        queryid: '210100000000'
      }
      createPost(data).then(ret => {
        if (ret.data.data.result === '1') {
          this.AddressList = ret.data.data.data
        }
      })
    },
    // 专业名称
    findZYNameList () {
      let data = {
        apiName: 'sq4zycode'
      }
      createPost(data).then(ret => {
        if (ret.data.data.result === '1') {
          this.ZYMCList = ret.data.data.data
        }
      })
    },
    zynamea (val) {
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        this.formDynamic.items[i].zyName = JSON.parse(val).label
        this.formDynamic.items[i].zyCode = JSON.parse(val).id
      }
    },
    // 用工形式
    findTypeList () {
      let data = {
        apiName: 'sq4zdlist',
        aaa100: 'ACB20A'
      }
      createPost(data).then(ret => {
        /*   if (ret.data.data.result === '1') { */
        this.typeList = ret.data.data.data
        /*   } */
      })
    },
    // 岗位描述
    gwjieshao () {
      let data = {
        apiName: 'sq4zdlist',
        aaa100: 'ACB216'
      }
      createPost(data).then(ret => {
        /* if (ret.data.data.result === '1') { */
        this.gangweiList = ret.data.data.data
        /*   } */
      })
    },
    // 招聘工种名称
    findJobNameList () {
      let data = {
        apiName: 'sq4gjzyfl'
      }
      createPost(data).then(ret => {
        if (ret.data.data.result === '1') {
          this.jobNameList = ret.data.data.data
        }
      })
    },
    // 招聘工种代码
    findJobList () {
      let data = {
        apiName: 'sq4gjzyfl'
      }
      createPost(data).then(ret => {
        if (ret.data.data.result === '1') {
          this.jobList = ret.data.data.data
        }
      })
    },
    // 经办日期
    saveTime () {
      let data = new Date()
      /* let HH = data.getHours()
      HH = HH < 10 ? ('0' + HH) : HH
      let mm = data.getMinutes()
      mm = mm < 10 ? ('0' + mm) : mm
      let ss = data.getSeconds()
      ss = ss < 10 ? ('0' + ss) : ss */
      this.recruitItem.aae036 = date2str(data) /* + ' ' + HH + ':' + mm + ':' + ss */
    },
    test () {
      /* this.recruitItem.zpgw = [] */
      let reg1 = /^1[3456789]\d{9}$/
      // 添加工作岗位
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        let data1 = {
          aae031: date2str(this.formDynamic.items[i].endTime),
          aca111: this.formDynamic.items[i].code,
          aca112: this.formDynamic.items[i].name,
          acb216: this.formDynamic.items[i].post,
          acb20A: this.formDynamic.items[i].type,
          acb21D: this.formDynamic.items[i].manNum,
          acb21E: this.formDynamic.items[i].womNum,
          acb21F: this.formDynamic.items[i].num,
          acb221: this.formDynamic.items[i].limitAge,
          acb222: this.formDynamic.items[i].maxAge,
          acb241: this.formDynamic.items[i].minSalary,
          acb242: this.formDynamic.items[i].maxSalary,
          acb244: this.formDynamic.items[i].fuli,
          aac011: this.formDynamic.items[i].culture,
          aac183: this.formDynamic.items[i].zyCode,
          aac184: this.formDynamic.items[i].zyName,
          aac033: this.formDynamic.items[i].health,
          aac217: this.formDynamic.items[i].year,
          acb21s: this.formDynamic.items[i].address,
          aab301: this.formDynamic.items[i].guihua,
          aaa021: this.formDynamic.items[i].gzName,
          aae013: this.formDynamic.items[i].beizhu,
          aae036: date2str(this.formDynamic.items[i].jingban)
        }
        this.recruitItem.zpgw.push(data1)
      }
      if (this.recruitItem.aab003 === '' || this.recruitItem.aab003 === undefined) {
        this.$Notice.error({ title: '请输入社会统一信用代码', desc: '' })
        return false
      } else if (this.recruitItem.aab004 === '' || this.recruitItem.aab004 === undefined) {
        this.$Notice.error({ title: '请输入单位名称', desc: '' })
        return false
      } else if (this.recruitItem.aab022 === '' || this.recruitItem.aab022 === undefined) {
        this.$Notice.error({ title: '请选择所属行业名称', desc: '' })
        return false
      } else if (this.recruitItem.aab023 === '' || this.recruitItem.aab023 === undefined) {
        this.$Notice.error({ title: '请选择所属行业代码', desc: '' })
        return false
      } else if (this.recruitItem.aab020 === '' || this.recruitItem.aab020 === undefined) {
        this.$Notice.error({ title: '请选择经济类型', desc: '' })
        return false
      } else if (this.recruitItem.aab054 === '' || this.recruitItem.aab054 === undefined) {
        this.$Notice.error({ title: '请输入产业类别', desc: '' })
        return false
      } else if (this.recruitItem.aae006 === '' || this.recruitItem.aae006 === undefined) {
        this.$Notice.error({ title: '请输入单位地址', desc: '' })
        return false
      } else if (this.recruitItem.aab092 === '' || this.recruitItem.aab092 === undefined) {
        this.$Notice.error({ title: '请输入单位简介', desc: '' })
        return false
      } else if (this.recruitItem.aae004 === '' || this.recruitItem.aae004 === undefined) {
        this.$Notice.error({ title: '请输入联系人', desc: '' })
        return false
      } else if (reg1.test(this.recruitItem.aae005) === false) {
        this.$Notice.error({ title: '手机号不合法', desc: '' })
        return false
      } else if (this.recruitItem.aae036 === '' || this.recruitItem.aae036 === undefined) {
        this.$Notice.error({ title: '请输入经办日期', desc: '' })
        return false
      } else {
        this.$emit('recruitItem', this.recruitItem)
      }
    },
    // 添加工作经验
    handleAdd () {
      this.index++
      this.formDynamic.items.push({
        endTime: '',
        code: '',
        name: '',
        post: '',
        type: '',
        manNum: '',
        womNum: '',
        num: '',
        limitAge: '',
        maxAge: '',
        minSalary: '',
        maxSalary: '',
        fuli: '',
        health: '',
        culture: '',
        zyCode: '',
        year: '',
        address: '',
        zyName: '',
        guihua: '',
        gzName: '',
        beizhu: '',
        jingban: '',
        index: this.index,
        status: 1
      })
    }
  },
  mounted () {
    this.findJobList()
    this.findAddressList()
    this.findZYNameList()
    this.findTypeList()
    this.findJobNameList()
    this.gongzhong()
    this.gwjieshao()
  }
}
</script>

<style scoped>
  .ivu-row{
    margin-bottom: 15px;
  }
  .add{
    width: 218px;
    margin-bottom: 20px;
  }
</style>
